package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(61)
public class BinglinGameStrategy extends BaseGameStrategy {

    public static final String URL = "http://114.66.45.129:81/htss/gm/gmquery.php";


    /**
     * action: sendmoney
     * qid: 1
     * uid: 宪州籍太尉
     * gmcode: 123
     * chargetype: 1
     * chargenum: 1
     *
     * {"message":"发送成功！玩家昵称：宪州籍太尉！","errno":0}
     * @param item
     * @return
     */
    @GongnengMethod(6101)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("gmcode", "diyao88");
        params.add("action", "sendmoney");
        params.add("qid", "1");

        params.add("uid", item.uid);
        params.add("chargenum", item.number);
        params.add("chargetype", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params, "message");
    }

    /**
     * action: senditem
     * qid: 1
     * uid: 宪州籍太尉
     * gmcode: 123
     * itemid: iron
     * itemnum: 123
     *
     * @param item
     * @return
     */
    @GongnengMethod(6102)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("gmcode", "diyao88");
        params.add("action", "senditem");
        params.add("qid", "1");

        params.add("uid", item.uid);
        params.add("itemnum", item.number);
        params.add("itemid", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(URL, params, "message");
    }



    @GongnengMethod(9)
    public String clear(SendItem item) {
        System.out.println("清除成功");
        return "清除成功";
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "宪州籍太尉";
        item.number = "121";
        item.itemId = "iron";
        System.out.println(new BinglinGameStrategy().mail(item));
    }
}

